package com.gitee.wsl.evaluator.token

/**
 * Variable token
 *
 * @author dennis
 */
open class Variable(name: String?, lineNo: Int, startIndex: Int) : AbstractToken<Any?>(name,lineNo, startIndex) {
    var isQuote: Boolean = false

    override val type: Token.TokenType = Token.TokenType.Variable


    override fun getValue(env: Map<String, Any?>?): Any? {
        return if (env != null) {
            env[lexeme]
        } else {
            lexeme
        }
    }


    override fun toString(): String {
        var index = ",index=$startIndex"
        if (startIndex == -1) {
            index = ""
        }
        return "[type='variable',lexeme='$lexeme'$index]"
    }

    companion object {
        
        /**
         * Boolean value true
         */
        val TRUE: Variable = object: Variable("true", 0, -1) {
            
            override fun getValue(env: Map<String, Any?>?): Any {
                return true
            }
        }

        /**
         * Boolean value false
         */
        val FALSE: Variable = object : Variable("false", 0, -1) {
            
            override fun getValue(env: Map<String, Any?>?): Any {
                return false
            }
        }

        /**
         * Boolean value false
         */
        val NIL: Variable = object : Variable("nil", 0, -1) {
            private val serialVersionUID = 5405079118962650113L

            override fun getValue(env: Map<String, Any?>?): Any? {
                return null
            }
        }


        /**
         * Lambda keyword
         */
        val LAMBDA: Variable = object : Variable("lambda", 0, -1) {
            private val serialVersionUID = 5239852591646934183L

            override fun getValue(env: Map<String, Any?>?): Any {
                return this
            }
        }

        /**
         * end keyword
         */
        val END: Variable = object : Variable("end", 0, -1) {
            private val serialVersionUID = 1381194991295087667L

            override fun getValue(env: Map<String, Any?>?): Any {
                return this
            }
        }

        /**
         * if keyword
         */
        val IF: Variable = object : Variable("if", 0, -1) {
            private val serialVersionUID = 371294588236388238L

            override fun getValue(env: Map<String, Any?>?): Any {
                return this
            }
        }

        /**
         * else keyword
         */
        val ELSE: Variable = object : Variable("else", 0, -1) {
            private val serialVersionUID = -8680881360673170940L

            override fun getValue(env: Map<String, Any?>?): Any {
                return this
            }
        }


        /**
         * for keyword
         */
        val FOR: Variable = object : Variable("for", 0, -1) {
            private val serialVersionUID = -8264017729568522971L

            override fun getValue(env: Map<String, Any?>?): Any {
                return this
            }
        }

        /**
         * in keyword
         */
        val IN: Variable = object : Variable("in", 0, -1) {
            private val serialVersionUID = -4622016350260111762L

            override fun getValue(env: Map<String, Any?>?): Any {
                return this
            }
        }

        /**
         * return keyword
         */
        val RETURN: Variable = object : Variable("return", 0, -1) {
            private val serialVersionUID = 720528094830222144L

            override fun getValue(env: Map<String, Any?>?): Any {
                return this
            }
        }

        /**
         * return keyword
         */
        val BREAK: Variable = object : Variable("break", 0, -1) {
            private val serialVersionUID = -3811349935845126666L

            override fun getValue(env: Map<String, Any?>?): Any {
                return this
            }
        }

        /**
         * return keyword
         */
        val CONTINUE: Variable = object : Variable("continue", 0, -1) {
            private val serialVersionUID = -97078099593768562L

            override fun getValue(env: Map<String, Any?>?): Any {
                return this
            }
        }

        /**
         * let keyword
         */
        val LET: Variable = object : Variable("let", 0, -1) {
            private val serialVersionUID = 8947676572495899744L

            override fun getValue(env: Map<String, Any?>?): Any {
                return this
            }
        }

        /**
         * while keyword
         */
        val WHILE: Variable = object : Variable("while", 0, -1) {
            private val serialVersionUID = -7452208104495691948L

            override fun getValue(env: Map<String, Any?>?): Any {
                return this
            }
        }

        /**
         * fn keyword
         */
        val FN: Variable = object : Variable("fn", 0, -1) {
            private val serialVersionUID = 1310362304034338211L

            override fun getValue(env: Map<String, Any?>?): Any {
                return this
            }
        }

        /**
         * elsif keyword
         */
        val ELSIF: Variable = object : Variable("elsif", 0, -1) {
            private val serialVersionUID = 9179033352817183568L

            override fun getValue(env: Map<String, Any?>?): Any {
                return this
            }
        }

        /**
         * elsif keyword
         */
        val TRY: Variable = object : Variable("try", 0, -1) {
            private val serialVersionUID = -5941442994484723465L

            override fun getValue(env: Map<String, Any?>?): Any {
                return this
            }
        }

        val CATCH: Variable = object : Variable("catch", 0, -1) {
            private val serialVersionUID = 5648899950149965053L

            override fun getValue(env: Map<String, Any?>?): Any {
                return this
            }
        }

        val FINALLY: Variable = object : Variable("finally", 0, -1) {
            private val serialVersionUID = 4620910964773812463L

            override fun getValue(env: Map<String, Any?>?): Any {
                return this
            }
        }

        val THROW: Variable = object : Variable("throw", 0, -1) {
            private val serialVersionUID = 113057346952612067L

            override fun getValue(env: Map<String, Any?>?): Any {
                return this
            }
        }


        val NEW: Variable = object : Variable("new", 0, -1) {
            private val serialVersionUID = 113057346952612067L

            override fun getValue(env: Map<String, Any?>?): Any {
                return this
            }
        }


        val USE: Variable = object : Variable("use", 0, -1) {
            private val serialVersionUID = 113057346952612067L

            override fun getValue(env: Map<String, Any?>?): Any {
                return this
            }
        }
    }
}